<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>md5.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_crypt_md5.js.html">md5.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview MD5 cryptographic hash.
<a name="line17"></a> * Implementation of http://tools.ietf.org/html/rfc1321 with common
<a name="line18"></a> * optimizations and tweaks (see http://en.wikipedia.org/wiki/MD5).
<a name="line19"></a> *
<a name="line20"></a> * Usage:
<a name="line21"></a> *   var md5 = new goog.crypt.Md5();
<a name="line22"></a> *   md5.update(bytes);
<a name="line23"></a> *   var hash = md5.digest();
<a name="line24"></a> *
<a name="line25"></a> * Performance:
<a name="line26"></a> *   Chrome 23              ~680 Mbit/s
<a name="line27"></a> *   Chrome 13 (in a VM)    ~250 Mbit/s
<a name="line28"></a> *   Firefox 6.0 (in a VM)  ~100 Mbit/s
<a name="line29"></a> *   IE9 (in a VM)           ~27 Mbit/s
<a name="line30"></a> *   Firefox 3.6             ~15 Mbit/s
<a name="line31"></a> *   IE8 (in a VM)           ~13 Mbit/s
<a name="line32"></a> *
<a name="line33"></a> */
<a name="line34"></a>
<a name="line35"></a>goog.provide(&#39;goog.crypt.Md5&#39;);
<a name="line36"></a>
<a name="line37"></a>goog.require(&#39;goog.crypt.Hash&#39;);
<a name="line38"></a>
<a name="line39"></a>
<a name="line40"></a>
<a name="line41"></a>/**
<a name="line42"></a> * MD5 cryptographic hash constructor.
<a name="line43"></a> * @constructor
<a name="line44"></a> * @extends {goog.crypt.Hash}
<a name="line45"></a> * @final
<a name="line46"></a> * @struct
<a name="line47"></a> */
<a name="line48"></a>goog.crypt.Md5 = function() {
<a name="line49"></a>  goog.crypt.Md5.base(this, &#39;constructor&#39;);
<a name="line50"></a>
<a name="line51"></a>  this.blockSize = 512 / 8;
<a name="line52"></a>
<a name="line53"></a>  /**
<a name="line54"></a>   * Holds the current values of accumulated A-D variables (MD buffer).
<a name="line55"></a>   * @type {Array.&lt;number&gt;}
<a name="line56"></a>   * @private
<a name="line57"></a>   */
<a name="line58"></a>  this.chain_ = new Array(4);
<a name="line59"></a>
<a name="line60"></a>  /**
<a name="line61"></a>   * A buffer holding the data until the whole block can be processed.
<a name="line62"></a>   * @type {Array.&lt;number&gt;}
<a name="line63"></a>   * @private
<a name="line64"></a>   */
<a name="line65"></a>  this.block_ = new Array(this.blockSize);
<a name="line66"></a>
<a name="line67"></a>  /**
<a name="line68"></a>   * The length of yet-unprocessed data as collected in the block.
<a name="line69"></a>   * @type {number}
<a name="line70"></a>   * @private
<a name="line71"></a>   */
<a name="line72"></a>  this.blockLength_ = 0;
<a name="line73"></a>
<a name="line74"></a>  /**
<a name="line75"></a>   * The total length of the message so far.
<a name="line76"></a>   * @type {number}
<a name="line77"></a>   * @private
<a name="line78"></a>   */
<a name="line79"></a>  this.totalLength_ = 0;
<a name="line80"></a>
<a name="line81"></a>  this.reset();
<a name="line82"></a>};
<a name="line83"></a>goog.inherits(goog.crypt.Md5, goog.crypt.Hash);
<a name="line84"></a>
<a name="line85"></a>
<a name="line86"></a>/**
<a name="line87"></a> * Integer rotation constants used by the abbreviated implementation.
<a name="line88"></a> * They are hardcoded in the unrolled implementation, so it is left
<a name="line89"></a> * here commented out.
<a name="line90"></a> * @type {Array.&lt;number&gt;}
<a name="line91"></a> * @private
<a name="line92"></a> *
<a name="line93"></a>goog.crypt.Md5.S_ = [
<a name="line94"></a>  7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
<a name="line95"></a>  5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
<a name="line96"></a>  4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
<a name="line97"></a>  6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
<a name="line98"></a>];
<a name="line99"></a> */
<a name="line100"></a>
<a name="line101"></a>/**
<a name="line102"></a> * Sine function constants used by the abbreviated implementation.
<a name="line103"></a> * They are hardcoded in the unrolled implementation, so it is left
<a name="line104"></a> * here commented out.
<a name="line105"></a> * @type {Array.&lt;number&gt;}
<a name="line106"></a> * @private
<a name="line107"></a> *
<a name="line108"></a>goog.crypt.Md5.T_ = [
<a name="line109"></a>  0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
<a name="line110"></a>  0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
<a name="line111"></a>  0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
<a name="line112"></a>  0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
<a name="line113"></a>  0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
<a name="line114"></a>  0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
<a name="line115"></a>  0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
<a name="line116"></a>  0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
<a name="line117"></a>  0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
<a name="line118"></a>  0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
<a name="line119"></a>  0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
<a name="line120"></a>  0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
<a name="line121"></a>  0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
<a name="line122"></a>  0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
<a name="line123"></a>  0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
<a name="line124"></a>  0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
<a name="line125"></a>];
<a name="line126"></a> */
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/** @override */
<a name="line130"></a>goog.crypt.Md5.prototype.reset = function() {
<a name="line131"></a>  this.chain_[0] = 0x67452301;
<a name="line132"></a>  this.chain_[1] = 0xefcdab89;
<a name="line133"></a>  this.chain_[2] = 0x98badcfe;
<a name="line134"></a>  this.chain_[3] = 0x10325476;
<a name="line135"></a>
<a name="line136"></a>  this.blockLength_ = 0;
<a name="line137"></a>  this.totalLength_ = 0;
<a name="line138"></a>};
<a name="line139"></a>
<a name="line140"></a>
<a name="line141"></a>/**
<a name="line142"></a> * Internal compress helper function. It takes a block of data (64 bytes)
<a name="line143"></a> * and updates the accumulator.
<a name="line144"></a> * @param {Array.&lt;number&gt;|Uint8Array|string} buf The block to compress.
<a name="line145"></a> * @param {number=} opt_offset Offset of the block in the buffer.
<a name="line146"></a> * @private
<a name="line147"></a> */
<a name="line148"></a>goog.crypt.Md5.prototype.compress_ = function(buf, opt_offset) {
<a name="line149"></a>  if (!opt_offset) {
<a name="line150"></a>    opt_offset = 0;
<a name="line151"></a>  }
<a name="line152"></a>
<a name="line153"></a>  // We allocate the array every time, but it&#39;s cheap in practice.
<a name="line154"></a>  var X = new Array(16);
<a name="line155"></a>
<a name="line156"></a>  // Get 16 little endian words. It is not worth unrolling this for Chrome 11.
<a name="line157"></a>  if (goog.isString(buf)) {
<a name="line158"></a>    for (var i = 0; i &lt; 16; ++i) {
<a name="line159"></a>      X[i] = (buf.charCodeAt(opt_offset++)) |
<a name="line160"></a>             (buf.charCodeAt(opt_offset++) &lt;&lt; 8) |
<a name="line161"></a>             (buf.charCodeAt(opt_offset++) &lt;&lt; 16) |
<a name="line162"></a>             (buf.charCodeAt(opt_offset++) &lt;&lt; 24);
<a name="line163"></a>    }
<a name="line164"></a>  } else {
<a name="line165"></a>    for (var i = 0; i &lt; 16; ++i) {
<a name="line166"></a>      X[i] = (buf[opt_offset++]) |
<a name="line167"></a>             (buf[opt_offset++] &lt;&lt; 8) |
<a name="line168"></a>             (buf[opt_offset++] &lt;&lt; 16) |
<a name="line169"></a>             (buf[opt_offset++] &lt;&lt; 24);
<a name="line170"></a>    }
<a name="line171"></a>  }
<a name="line172"></a>
<a name="line173"></a>  var A = this.chain_[0];
<a name="line174"></a>  var B = this.chain_[1];
<a name="line175"></a>  var C = this.chain_[2];
<a name="line176"></a>  var D = this.chain_[3];
<a name="line177"></a>  var sum = 0;
<a name="line178"></a>
<a name="line179"></a>  /*
<a name="line180"></a>   * This is an abbreviated implementation, it is left here commented out for
<a name="line181"></a>   * reference purposes. See below for an unrolled version in use.
<a name="line182"></a>   *
<a name="line183"></a>  var f, n, tmp;
<a name="line184"></a>  for (var i = 0; i &lt; 64; ++i) {
<a name="line185"></a>
<a name="line186"></a>    if (i &lt; 16) {
<a name="line187"></a>      f = (D ^ (B &amp; (C ^ D)));
<a name="line188"></a>      n = i;
<a name="line189"></a>    } else if (i &lt; 32) {
<a name="line190"></a>      f = (C ^ (D &amp; (B ^ C)));
<a name="line191"></a>      n = (5 * i + 1) % 16;
<a name="line192"></a>    } else if (i &lt; 48) {
<a name="line193"></a>      f = (B ^ C ^ D);
<a name="line194"></a>      n = (3 * i + 5) % 16;
<a name="line195"></a>    } else {
<a name="line196"></a>      f = (C ^ (B | (~D)));
<a name="line197"></a>      n = (7 * i) % 16;
<a name="line198"></a>    }
<a name="line199"></a>
<a name="line200"></a>    tmp = D;
<a name="line201"></a>    D = C;
<a name="line202"></a>    C = B;
<a name="line203"></a>    sum = (A + f + goog.crypt.Md5.T_[i] + X[n]) &amp; 0xffffffff;
<a name="line204"></a>    B += ((sum &lt;&lt; goog.crypt.Md5.S_[i]) &amp; 0xffffffff) |
<a name="line205"></a>         (sum &gt;&gt;&gt; (32 - goog.crypt.Md5.S_[i]));
<a name="line206"></a>    A = tmp;
<a name="line207"></a>  }
<a name="line208"></a>   */
<a name="line209"></a>
<a name="line210"></a>  /*
<a name="line211"></a>   * This is an unrolled MD5 implementation, which gives ~30% speedup compared
<a name="line212"></a>   * to the abbreviated implementation above, as measured on Chrome 11. It is
<a name="line213"></a>   * important to keep 32-bit croppings to minimum and inline the integer
<a name="line214"></a>   * rotation.
<a name="line215"></a>   */
<a name="line216"></a>  sum = (A + (D ^ (B &amp; (C ^ D))) + X[0] + 0xd76aa478) &amp; 0xffffffff;
<a name="line217"></a>  A = B + (((sum &lt;&lt; 7) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 25));
<a name="line218"></a>  sum = (D + (C ^ (A &amp; (B ^ C))) + X[1] + 0xe8c7b756) &amp; 0xffffffff;
<a name="line219"></a>  D = A + (((sum &lt;&lt; 12) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 20));
<a name="line220"></a>  sum = (C + (B ^ (D &amp; (A ^ B))) + X[2] + 0x242070db) &amp; 0xffffffff;
<a name="line221"></a>  C = D + (((sum &lt;&lt; 17) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 15));
<a name="line222"></a>  sum = (B + (A ^ (C &amp; (D ^ A))) + X[3] + 0xc1bdceee) &amp; 0xffffffff;
<a name="line223"></a>  B = C + (((sum &lt;&lt; 22) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 10));
<a name="line224"></a>  sum = (A + (D ^ (B &amp; (C ^ D))) + X[4] + 0xf57c0faf) &amp; 0xffffffff;
<a name="line225"></a>  A = B + (((sum &lt;&lt; 7) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 25));
<a name="line226"></a>  sum = (D + (C ^ (A &amp; (B ^ C))) + X[5] + 0x4787c62a) &amp; 0xffffffff;
<a name="line227"></a>  D = A + (((sum &lt;&lt; 12) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 20));
<a name="line228"></a>  sum = (C + (B ^ (D &amp; (A ^ B))) + X[6] + 0xa8304613) &amp; 0xffffffff;
<a name="line229"></a>  C = D + (((sum &lt;&lt; 17) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 15));
<a name="line230"></a>  sum = (B + (A ^ (C &amp; (D ^ A))) + X[7] + 0xfd469501) &amp; 0xffffffff;
<a name="line231"></a>  B = C + (((sum &lt;&lt; 22) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 10));
<a name="line232"></a>  sum = (A + (D ^ (B &amp; (C ^ D))) + X[8] + 0x698098d8) &amp; 0xffffffff;
<a name="line233"></a>  A = B + (((sum &lt;&lt; 7) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 25));
<a name="line234"></a>  sum = (D + (C ^ (A &amp; (B ^ C))) + X[9] + 0x8b44f7af) &amp; 0xffffffff;
<a name="line235"></a>  D = A + (((sum &lt;&lt; 12) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 20));
<a name="line236"></a>  sum = (C + (B ^ (D &amp; (A ^ B))) + X[10] + 0xffff5bb1) &amp; 0xffffffff;
<a name="line237"></a>  C = D + (((sum &lt;&lt; 17) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 15));
<a name="line238"></a>  sum = (B + (A ^ (C &amp; (D ^ A))) + X[11] + 0x895cd7be) &amp; 0xffffffff;
<a name="line239"></a>  B = C + (((sum &lt;&lt; 22) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 10));
<a name="line240"></a>  sum = (A + (D ^ (B &amp; (C ^ D))) + X[12] + 0x6b901122) &amp; 0xffffffff;
<a name="line241"></a>  A = B + (((sum &lt;&lt; 7) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 25));
<a name="line242"></a>  sum = (D + (C ^ (A &amp; (B ^ C))) + X[13] + 0xfd987193) &amp; 0xffffffff;
<a name="line243"></a>  D = A + (((sum &lt;&lt; 12) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 20));
<a name="line244"></a>  sum = (C + (B ^ (D &amp; (A ^ B))) + X[14] + 0xa679438e) &amp; 0xffffffff;
<a name="line245"></a>  C = D + (((sum &lt;&lt; 17) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 15));
<a name="line246"></a>  sum = (B + (A ^ (C &amp; (D ^ A))) + X[15] + 0x49b40821) &amp; 0xffffffff;
<a name="line247"></a>  B = C + (((sum &lt;&lt; 22) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 10));
<a name="line248"></a>  sum = (A + (C ^ (D &amp; (B ^ C))) + X[1] + 0xf61e2562) &amp; 0xffffffff;
<a name="line249"></a>  A = B + (((sum &lt;&lt; 5) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 27));
<a name="line250"></a>  sum = (D + (B ^ (C &amp; (A ^ B))) + X[6] + 0xc040b340) &amp; 0xffffffff;
<a name="line251"></a>  D = A + (((sum &lt;&lt; 9) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 23));
<a name="line252"></a>  sum = (C + (A ^ (B &amp; (D ^ A))) + X[11] + 0x265e5a51) &amp; 0xffffffff;
<a name="line253"></a>  C = D + (((sum &lt;&lt; 14) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 18));
<a name="line254"></a>  sum = (B + (D ^ (A &amp; (C ^ D))) + X[0] + 0xe9b6c7aa) &amp; 0xffffffff;
<a name="line255"></a>  B = C + (((sum &lt;&lt; 20) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 12));
<a name="line256"></a>  sum = (A + (C ^ (D &amp; (B ^ C))) + X[5] + 0xd62f105d) &amp; 0xffffffff;
<a name="line257"></a>  A = B + (((sum &lt;&lt; 5) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 27));
<a name="line258"></a>  sum = (D + (B ^ (C &amp; (A ^ B))) + X[10] + 0x02441453) &amp; 0xffffffff;
<a name="line259"></a>  D = A + (((sum &lt;&lt; 9) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 23));
<a name="line260"></a>  sum = (C + (A ^ (B &amp; (D ^ A))) + X[15] + 0xd8a1e681) &amp; 0xffffffff;
<a name="line261"></a>  C = D + (((sum &lt;&lt; 14) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 18));
<a name="line262"></a>  sum = (B + (D ^ (A &amp; (C ^ D))) + X[4] + 0xe7d3fbc8) &amp; 0xffffffff;
<a name="line263"></a>  B = C + (((sum &lt;&lt; 20) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 12));
<a name="line264"></a>  sum = (A + (C ^ (D &amp; (B ^ C))) + X[9] + 0x21e1cde6) &amp; 0xffffffff;
<a name="line265"></a>  A = B + (((sum &lt;&lt; 5) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 27));
<a name="line266"></a>  sum = (D + (B ^ (C &amp; (A ^ B))) + X[14] + 0xc33707d6) &amp; 0xffffffff;
<a name="line267"></a>  D = A + (((sum &lt;&lt; 9) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 23));
<a name="line268"></a>  sum = (C + (A ^ (B &amp; (D ^ A))) + X[3] + 0xf4d50d87) &amp; 0xffffffff;
<a name="line269"></a>  C = D + (((sum &lt;&lt; 14) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 18));
<a name="line270"></a>  sum = (B + (D ^ (A &amp; (C ^ D))) + X[8] + 0x455a14ed) &amp; 0xffffffff;
<a name="line271"></a>  B = C + (((sum &lt;&lt; 20) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 12));
<a name="line272"></a>  sum = (A + (C ^ (D &amp; (B ^ C))) + X[13] + 0xa9e3e905) &amp; 0xffffffff;
<a name="line273"></a>  A = B + (((sum &lt;&lt; 5) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 27));
<a name="line274"></a>  sum = (D + (B ^ (C &amp; (A ^ B))) + X[2] + 0xfcefa3f8) &amp; 0xffffffff;
<a name="line275"></a>  D = A + (((sum &lt;&lt; 9) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 23));
<a name="line276"></a>  sum = (C + (A ^ (B &amp; (D ^ A))) + X[7] + 0x676f02d9) &amp; 0xffffffff;
<a name="line277"></a>  C = D + (((sum &lt;&lt; 14) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 18));
<a name="line278"></a>  sum = (B + (D ^ (A &amp; (C ^ D))) + X[12] + 0x8d2a4c8a) &amp; 0xffffffff;
<a name="line279"></a>  B = C + (((sum &lt;&lt; 20) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 12));
<a name="line280"></a>  sum = (A + (B ^ C ^ D) + X[5] + 0xfffa3942) &amp; 0xffffffff;
<a name="line281"></a>  A = B + (((sum &lt;&lt; 4) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 28));
<a name="line282"></a>  sum = (D + (A ^ B ^ C) + X[8] + 0x8771f681) &amp; 0xffffffff;
<a name="line283"></a>  D = A + (((sum &lt;&lt; 11) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 21));
<a name="line284"></a>  sum = (C + (D ^ A ^ B) + X[11] + 0x6d9d6122) &amp; 0xffffffff;
<a name="line285"></a>  C = D + (((sum &lt;&lt; 16) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 16));
<a name="line286"></a>  sum = (B + (C ^ D ^ A) + X[14] + 0xfde5380c) &amp; 0xffffffff;
<a name="line287"></a>  B = C + (((sum &lt;&lt; 23) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 9));
<a name="line288"></a>  sum = (A + (B ^ C ^ D) + X[1] + 0xa4beea44) &amp; 0xffffffff;
<a name="line289"></a>  A = B + (((sum &lt;&lt; 4) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 28));
<a name="line290"></a>  sum = (D + (A ^ B ^ C) + X[4] + 0x4bdecfa9) &amp; 0xffffffff;
<a name="line291"></a>  D = A + (((sum &lt;&lt; 11) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 21));
<a name="line292"></a>  sum = (C + (D ^ A ^ B) + X[7] + 0xf6bb4b60) &amp; 0xffffffff;
<a name="line293"></a>  C = D + (((sum &lt;&lt; 16) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 16));
<a name="line294"></a>  sum = (B + (C ^ D ^ A) + X[10] + 0xbebfbc70) &amp; 0xffffffff;
<a name="line295"></a>  B = C + (((sum &lt;&lt; 23) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 9));
<a name="line296"></a>  sum = (A + (B ^ C ^ D) + X[13] + 0x289b7ec6) &amp; 0xffffffff;
<a name="line297"></a>  A = B + (((sum &lt;&lt; 4) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 28));
<a name="line298"></a>  sum = (D + (A ^ B ^ C) + X[0] + 0xeaa127fa) &amp; 0xffffffff;
<a name="line299"></a>  D = A + (((sum &lt;&lt; 11) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 21));
<a name="line300"></a>  sum = (C + (D ^ A ^ B) + X[3] + 0xd4ef3085) &amp; 0xffffffff;
<a name="line301"></a>  C = D + (((sum &lt;&lt; 16) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 16));
<a name="line302"></a>  sum = (B + (C ^ D ^ A) + X[6] + 0x04881d05) &amp; 0xffffffff;
<a name="line303"></a>  B = C + (((sum &lt;&lt; 23) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 9));
<a name="line304"></a>  sum = (A + (B ^ C ^ D) + X[9] + 0xd9d4d039) &amp; 0xffffffff;
<a name="line305"></a>  A = B + (((sum &lt;&lt; 4) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 28));
<a name="line306"></a>  sum = (D + (A ^ B ^ C) + X[12] + 0xe6db99e5) &amp; 0xffffffff;
<a name="line307"></a>  D = A + (((sum &lt;&lt; 11) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 21));
<a name="line308"></a>  sum = (C + (D ^ A ^ B) + X[15] + 0x1fa27cf8) &amp; 0xffffffff;
<a name="line309"></a>  C = D + (((sum &lt;&lt; 16) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 16));
<a name="line310"></a>  sum = (B + (C ^ D ^ A) + X[2] + 0xc4ac5665) &amp; 0xffffffff;
<a name="line311"></a>  B = C + (((sum &lt;&lt; 23) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 9));
<a name="line312"></a>  sum = (A + (C ^ (B | (~D))) + X[0] + 0xf4292244) &amp; 0xffffffff;
<a name="line313"></a>  A = B + (((sum &lt;&lt; 6) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 26));
<a name="line314"></a>  sum = (D + (B ^ (A | (~C))) + X[7] + 0x432aff97) &amp; 0xffffffff;
<a name="line315"></a>  D = A + (((sum &lt;&lt; 10) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 22));
<a name="line316"></a>  sum = (C + (A ^ (D | (~B))) + X[14] + 0xab9423a7) &amp; 0xffffffff;
<a name="line317"></a>  C = D + (((sum &lt;&lt; 15) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 17));
<a name="line318"></a>  sum = (B + (D ^ (C | (~A))) + X[5] + 0xfc93a039) &amp; 0xffffffff;
<a name="line319"></a>  B = C + (((sum &lt;&lt; 21) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 11));
<a name="line320"></a>  sum = (A + (C ^ (B | (~D))) + X[12] + 0x655b59c3) &amp; 0xffffffff;
<a name="line321"></a>  A = B + (((sum &lt;&lt; 6) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 26));
<a name="line322"></a>  sum = (D + (B ^ (A | (~C))) + X[3] + 0x8f0ccc92) &amp; 0xffffffff;
<a name="line323"></a>  D = A + (((sum &lt;&lt; 10) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 22));
<a name="line324"></a>  sum = (C + (A ^ (D | (~B))) + X[10] + 0xffeff47d) &amp; 0xffffffff;
<a name="line325"></a>  C = D + (((sum &lt;&lt; 15) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 17));
<a name="line326"></a>  sum = (B + (D ^ (C | (~A))) + X[1] + 0x85845dd1) &amp; 0xffffffff;
<a name="line327"></a>  B = C + (((sum &lt;&lt; 21) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 11));
<a name="line328"></a>  sum = (A + (C ^ (B | (~D))) + X[8] + 0x6fa87e4f) &amp; 0xffffffff;
<a name="line329"></a>  A = B + (((sum &lt;&lt; 6) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 26));
<a name="line330"></a>  sum = (D + (B ^ (A | (~C))) + X[15] + 0xfe2ce6e0) &amp; 0xffffffff;
<a name="line331"></a>  D = A + (((sum &lt;&lt; 10) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 22));
<a name="line332"></a>  sum = (C + (A ^ (D | (~B))) + X[6] + 0xa3014314) &amp; 0xffffffff;
<a name="line333"></a>  C = D + (((sum &lt;&lt; 15) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 17));
<a name="line334"></a>  sum = (B + (D ^ (C | (~A))) + X[13] + 0x4e0811a1) &amp; 0xffffffff;
<a name="line335"></a>  B = C + (((sum &lt;&lt; 21) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 11));
<a name="line336"></a>  sum = (A + (C ^ (B | (~D))) + X[4] + 0xf7537e82) &amp; 0xffffffff;
<a name="line337"></a>  A = B + (((sum &lt;&lt; 6) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 26));
<a name="line338"></a>  sum = (D + (B ^ (A | (~C))) + X[11] + 0xbd3af235) &amp; 0xffffffff;
<a name="line339"></a>  D = A + (((sum &lt;&lt; 10) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 22));
<a name="line340"></a>  sum = (C + (A ^ (D | (~B))) + X[2] + 0x2ad7d2bb) &amp; 0xffffffff;
<a name="line341"></a>  C = D + (((sum &lt;&lt; 15) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 17));
<a name="line342"></a>  sum = (B + (D ^ (C | (~A))) + X[9] + 0xeb86d391) &amp; 0xffffffff;
<a name="line343"></a>  B = C + (((sum &lt;&lt; 21) &amp; 0xffffffff) | (sum &gt;&gt;&gt; 11));
<a name="line344"></a>
<a name="line345"></a>  this.chain_[0] = (this.chain_[0] + A) &amp; 0xffffffff;
<a name="line346"></a>  this.chain_[1] = (this.chain_[1] + B) &amp; 0xffffffff;
<a name="line347"></a>  this.chain_[2] = (this.chain_[2] + C) &amp; 0xffffffff;
<a name="line348"></a>  this.chain_[3] = (this.chain_[3] + D) &amp; 0xffffffff;
<a name="line349"></a>};
<a name="line350"></a>
<a name="line351"></a>
<a name="line352"></a>/** @override */
<a name="line353"></a>goog.crypt.Md5.prototype.update = function(bytes, opt_length) {
<a name="line354"></a>  if (!goog.isDef(opt_length)) {
<a name="line355"></a>    opt_length = bytes.length;
<a name="line356"></a>  }
<a name="line357"></a>  var lengthMinusBlock = opt_length - this.blockSize;
<a name="line358"></a>
<a name="line359"></a>  // Copy some object properties to local variables in order to save on access
<a name="line360"></a>  // time from inside the loop (~10% speedup was observed on Chrome 11).
<a name="line361"></a>  var block = this.block_;
<a name="line362"></a>  var blockLength = this.blockLength_;
<a name="line363"></a>  var i = 0;
<a name="line364"></a>
<a name="line365"></a>  // The outer while loop should execute at most twice.
<a name="line366"></a>  while (i &lt; opt_length) {
<a name="line367"></a>    // When we have no data in the block to top up, we can directly process the
<a name="line368"></a>    // input buffer (assuming it contains sufficient data). This gives ~30%
<a name="line369"></a>    // speedup on Chrome 14 and ~70% speedup on Firefox 6.0, but requires that
<a name="line370"></a>    // the data is provided in large chunks (or in multiples of 64 bytes).
<a name="line371"></a>    if (blockLength == 0) {
<a name="line372"></a>      while (i &lt;= lengthMinusBlock) {
<a name="line373"></a>        this.compress_(bytes, i);
<a name="line374"></a>        i += this.blockSize;
<a name="line375"></a>      }
<a name="line376"></a>    }
<a name="line377"></a>
<a name="line378"></a>    if (goog.isString(bytes)) {
<a name="line379"></a>      while (i &lt; opt_length) {
<a name="line380"></a>        block[blockLength++] = bytes.charCodeAt(i++);
<a name="line381"></a>        if (blockLength == this.blockSize) {
<a name="line382"></a>          this.compress_(block);
<a name="line383"></a>          blockLength = 0;
<a name="line384"></a>          // Jump to the outer loop so we use the full-block optimization.
<a name="line385"></a>          break;
<a name="line386"></a>        }
<a name="line387"></a>      }
<a name="line388"></a>    } else {
<a name="line389"></a>      while (i &lt; opt_length) {
<a name="line390"></a>        block[blockLength++] = bytes[i++];
<a name="line391"></a>        if (blockLength == this.blockSize) {
<a name="line392"></a>          this.compress_(block);
<a name="line393"></a>          blockLength = 0;
<a name="line394"></a>          // Jump to the outer loop so we use the full-block optimization.
<a name="line395"></a>          break;
<a name="line396"></a>        }
<a name="line397"></a>      }
<a name="line398"></a>    }
<a name="line399"></a>  }
<a name="line400"></a>
<a name="line401"></a>  this.blockLength_ = blockLength;
<a name="line402"></a>  this.totalLength_ += opt_length;
<a name="line403"></a>};
<a name="line404"></a>
<a name="line405"></a>
<a name="line406"></a>/** @override */
<a name="line407"></a>goog.crypt.Md5.prototype.digest = function() {
<a name="line408"></a>  // This must accommodate at least 1 padding byte (0x80), 8 bytes of
<a name="line409"></a>  // total bitlength, and must end at a 64-byte boundary.
<a name="line410"></a>  var pad = new Array((this.blockLength_ &lt; 56 ?
<a name="line411"></a>                       this.blockSize :
<a name="line412"></a>                       this.blockSize * 2) - this.blockLength_);
<a name="line413"></a>
<a name="line414"></a>  // Add padding: 0x80 0x00*
<a name="line415"></a>  pad[0] = 0x80;
<a name="line416"></a>  for (var i = 1; i &lt; pad.length - 8; ++i) {
<a name="line417"></a>    pad[i] = 0;
<a name="line418"></a>  }
<a name="line419"></a>  // Add the total number of bits, little endian 64-bit integer.
<a name="line420"></a>  var totalBits = this.totalLength_ * 8;
<a name="line421"></a>  for (var i = pad.length - 8; i &lt; pad.length; ++i) {
<a name="line422"></a>    pad[i] = totalBits &amp; 0xff;
<a name="line423"></a>    totalBits /= 0x100; // Don&#39;t use bit-shifting here!
<a name="line424"></a>  }
<a name="line425"></a>  this.update(pad);
<a name="line426"></a>
<a name="line427"></a>  var digest = new Array(16);
<a name="line428"></a>  var n = 0;
<a name="line429"></a>  for (var i = 0; i &lt; 4; ++i) {
<a name="line430"></a>    for (var j = 0; j &lt; 32; j += 8) {
<a name="line431"></a>      digest[n++] = (this.chain_[i] &gt;&gt;&gt; j) &amp; 0xff;
<a name="line432"></a>    }
<a name="line433"></a>  }
<a name="line434"></a>  return digest;
<a name="line435"></a>};
</pre>


</body>
</html>
